package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.ConsultantInfo;
import gentle.entity.CustomerAppointmentInfo;
import gentle.entity.SearchCustomerAppointmentInfo;
import gentle.factory.PageFactory;
import gentle.service.ICustomerAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author py
 * @Date 2019年4月19日23:15:54
 */
@Controller
@RequestMapping("/customerAppointment")
public class CustomerAppointmentController extends BaseController {
    @Autowired
    ICustomerAppointmentService appointmentService;

    /**
     * 到店 预约查询列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(SearchCustomerAppointmentInfo info) {
        if(info.getAbbreviation() == null || info.getAbbreviation() == "" || info.getAbbreviation() == "null"){
            return null;
        }else{
            Page<CustomerAppointmentInfo> page = new PageFactory<CustomerAppointmentInfo>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<CustomerAppointmentInfo> list = appointmentService.selectPageListByQueryGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = appointmentService.selectPageListByQueryGetMap(page, info);
                }
                page.setRecords(list);
                page.setTotal(appointmentService.getQueryPagesCount(page, info));
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

    /**
     * 统计查询
     */
    @RequestMapping(value = "/total", method = RequestMethod.GET)
    @ResponseBody
    public List<ConsultantInfo> changeTotal(String startTime, String endTime, String oneChannelValue, String doctor,
                                            String twoChannelValue, String thrChannelValue, String fieldTc, String treatmentUnit,
                                            String sreach ,String abbreviation) throws Exception {
        return appointmentService.changeTotal(startTime,endTime,oneChannelValue,doctor,twoChannelValue,thrChannelValue,fieldTc,treatmentUnit,
                sreach,abbreviation);
    }
}